package ch04.d3;

public class Person {
    //多态
    public void feed(Animal animal){
        animal.eat();
        animal.roar();

        if(animal instanceof Cat){
            Cat c=(Cat)animal;//向下转型 强制类型转换
            c.catchMouse();
        }else if (animal instanceof Dog){
            Dog d=(Dog)animal;//向下转型 强制类型转换
            d.watchDoor();
        }

    }

    // 重载
    public void feed2(Dog d){
        d.eat();
        d.roar();
        d.watchDoor();
    }
    public void feed2(Cat d){
        d.eat();
        d.roar();
        d.catchMouse();
    }

}
